package com.tang.receiver.broadcastreceiver;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Created by tang on 2018/1/18.
 */

public class BootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // 在这里干你想干的事（启动一个Service，Activity等）

        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
        {
            Log.w("开机自启","");
        }
        switch (intent.getAction()) {
            case BluetoothAdapter.ACTION_STATE_CHANGED:
                int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
                switch (blueState) {
                    case BluetoothAdapter.STATE_TURNING_ON:
                        Log.e("TAG", "TURNING_ON");
                        break;
                    case BluetoothAdapter.STATE_ON:
                        Intent i = new Intent(context, MainActivity.class);
                        context.startActivity(i);
                        Log.e("TAG", "STATE_ON");
                        break;
                    case BluetoothAdapter.STATE_TURNING_OFF:
                        Log.e("TAG", "STATE_TURNING_OFF");
                        break;
                    case BluetoothAdapter.STATE_OFF:
                        Log.e("TAG", "STATE_OFF");
                        break;
                }
                break;
        }

    }





    }
